#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

int main()
{
    int n;
    string a;
    cin >> n;
    while (cin >> a, n--)
    {
        int cnt = 1;
        char c = a[0];
        for (int i = 0; i < a.size(); i++)
        {
            int j = i;
            while (j < a.size() && a[j] == a[i])
                j++;
            if (cnt < j - i)
            {
                cnt = j - i;
                c = a[i];
            }
            i = j - 1;
        }
        cout << c << ' ' << cnt << endl;
    }
    return 0;
}
